#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main()
{
    int d, b, i, c, e, f, g, h = 0;
    scanf("%d %d", &b, &c);
    i = b + 1;
    int a[i];
    for (d = 0; d <= b; d++)
        a[d] = 0;
    for (d = 1; d <= c; d++)
    {
        scanf("%d %d", &e, &f);
        for (g = e; g <= f; g++)
        {
            a[g] = 1;
        }

    }
    for (g = 0; g <= b; g++)
    {
        if (a[g] == 0)
            h += 1;
    }
    printf("%d", h);
}